﻿@model MessageDesignListModel
@using Nop.Plugin.Misc.MessageDesigner.Models;
@using System.Globalization;
@using Nop.Core.Infrastructure;
@using Nop.Web.Framework;
@using Nop.Web.Framework.UI;
@{
    //page title
    ViewBag.Title = T("Plugins.Misc.MessageDesigner").Text;
    var kendoVersion = "2014.1.318";
    Html.AppendScriptParts(string.Format("~/Scripts/kendo/{0}/kendo.web.min.js", kendoVersion));
    Html.AppendScriptParts("~/Scripts/jquery-1.10.2.min.js");

}
@Html.NopScripts(this.Url, ResourceLocation.Head)

@Html.HiddenFor(model => model.TemplateId)
@Html.HiddenFor(model => model.DesignId)
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Plugins.Misc.MessageDesigner")
    </div>
    <div class="options">
    </div>
</div>
<table width="100%">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.SearchStoreId):
        </td>
        <td class="adminData">
            @Html.DropDownList("SearchStoreId", Model.AvailableStores)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" id="search-designs" class="k-button" value="@T("Admin.Common.Search")" />
        </td>
    </tr>
</table>
<table class="adminContent">
    <tr>
        <td>
            <div id="designs-grid"></div>

            <script>
    $(document).ready(function () {
        $("#designs-grid").kendoGrid({
            dataSource: {
                type: "json",
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("DesignList", "MiscMessageDesigner"))",
                        type: "POST",
                        dataType: "json",
                        data: additionalData
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors"
                },
                error: function (e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                numeric: false,
                previousNext: false,
                info: false
            },
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [{
                field: "Name",
                title: "@T("Plugins.Misc.MessageDesigner.Fields.Name")",
                template: '# if (Selected == true) { #' +
                          '#=Name# <img src="@Url.Content("~/Administration/Content/images/")active-#=Selected#.gif" />' +
                          '# } else { #' +
                          '#=Name#' +
                          '# } #'
            }, {
                field: "AdminComment",
                title: "@T("Plugins.Misc.MessageDesigner.Fields.AdminComment")",
            }, {
                field: "Id",
                title: "@T("Admin.Common.Edit")",
                width: 100,
                template: '<a href="@Url.Content("~/MiscMessageDesigner/Edit/")#=Id#">@T("Admin.Common.Edit")</a>'
            }, {
                field: "Id",
                title: "@T("Plugins.Misc.MessageDesigner.Fields.View")",
                width: 100,
                template: '# if (Selected == true) { #' +
                          '<a  onclick="javascript:OpenWindow(\'@(Url.Action("ViewTemplate"))?templateId=@Model.TemplateId\', 800, 800, true); return false;" >@T("Plugins.Misc.MessageDesigner.Fields.View")</a>' +
                          '# } else { #' +
                          '<a  onclick="javascript:OpenWindow(\'@(Url.Action("ViewDesign"))?designId=#=Id#&templateId=@Model.TemplateId\', 800, 800, true); return false;" >@T("Plugins.Misc.MessageDesigner.Fields.View")</a>' +
                          '# } #'
            }, {
                field: "Id",
                title: "@T("Plugins.Misc.MessageDesigner.Fields.Select")",
                width: 100,
                template: '# if (Selected == true) { #' +
                          '<a href="@Url.Action("RemoveDesign")?templateId=@Model.TemplateId" style="color:red;" >@T("Plugins.Misc.MessageDesigner.RemoveDesign")</a>' +
                          '# } else { #' +
                          '<a href="@Url.Action("SelectDesign")?templateId=@(Model.TemplateId)&designId=#=Id#">@T("Plugins.Misc.MessageDesigner.Fields.Select")</a>' +
                          '# } #'
            }]
        });
    });
            </script>

            <script type="text/javascript">

                $(document).ready(function () {
                    //search button
                    $('#search-designs').click(function () {
                        //search
                        var grid = $('#designs-grid').data('kendoGrid');
                        grid.dataSource.read();
                    });
                });

                function additionalData() {
                    return {
                        SearchStoreId: $('#SearchStoreId').val(),
                        TemplateId: $('#TemplateId').val(),
                        DesignId: $('#DesignId').val()
                    };
                }
            </script>
        </td>
    </tr>
</table>
